package com.ruoyi.jnpfjava.service.LoginServiceImpl;

import com.ruoyi.jnpfjava.entity.AjaxResult;
import com.ruoyi.jnpfjava.entity.Login;
import com.ruoyi.jnpfjava.entity.LoginDTO;
import com.ruoyi.jnpfjava.mapper.LoginMapper;
import com.ruoyi.jnpfjava.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    public AjaxResult Login(String username, String password) {
        List<Login> login = loginMapper.Login();
        LoginDTO loginDTO = new LoginDTO();

        login.forEach(item -> {
            if (username.equals(item.getUsername()) && password.equals(item.getPassword())) {
                loginDTO.setToken("123456");
            }
        });
        if (loginDTO.getToken() != null) {
            return AjaxResult.success("登陆成功",loginDTO);
        } else {
            return AjaxResult.success("账号或密码错误");
        }
    }
}
